Motion Clouds are synthesized textures which aim at having similar characteristics as natural images but with controlled parameters. There are many ways to achieve these results and this notebook aims at showing that different procedures from different communities (neurioscience, modelling, computer vision, ...) may produce similar results.
import numpy as np
np.set_printoptions(precision=3, suppress=True)
import pylab
import matplotlib.pyplot as plt
%matplotlib inline
import sys
sys.path.append('..')
import MotionClouds as mc
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
import scipy.misc
lena = scipy.misc.lena() * 1.
lena -= lena.mean()
lena /= lena.std()
print lena.shape
plt.imshow(lena, cmap=plt.cm.gray)
def noise(image=lena):
for axis in [0, 1]:
image = np.roll(image, np.random.randint(image.shape[axis]), axis=axis)
return image
plt.imshow(noise(), cmap=plt.cm.gray)
plt.imshow(noise(), cmap=plt.cm.gray)
Now, we define the ARMA process as an averaging process with a certain time constant $\tau=30.$ (in frames).
def ARMA(image, tau=30.):
image = (1 - 1/tau)* image + 1/tau * noise()
return image
initializing
image = ARMA(lena)
plt.imshow(image, cmap=plt.cm.gray)
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
%cd..
N_frame = 1024
z = np.zeros((lena.shape[0], lena.shape[1], N_frame))
z[:, :, 0] = image
for i_frame in range(1, N_frame):
z[:, :, i_frame] = ARMA(z[:, :, i_frame-1])
mc.anim_save(.5 + .5*z, filename='results/arma')
mc.notebook = True
mc.in_show_video(name='arma')